﻿@using EmployeeLeaveSystem.Client.Components;
@using EmployeeLeaveSystem.Shared.Models;
@using EmployeeLeaveSystem.Shared;

@inject IMessageService _MessageService;
@inject HttpClient _HttpClient;
@inject ModalService _modalService;

<div>
    <Title Level="3">我的历史薪水</Title>
    <Paragraph>展示您最近几个月的薪水变化</Paragraph>
    <Paragraph> <TableShowSalary /> </Paragraph>
    <Title Level="3">我的历史薪水记录</Title>
    <Paragraph>您的历史薪水记录一览</Paragraph>
    <Paragraph>
        <Table DataSource="listSalarys">
            <GenerateColumns />
            <ActionColumn>
                <Button OnClick="()=>{OpenModalMove(context.Id);}">查看</Button>
            </ActionColumn>
        </Table>
    </Paragraph>
</div>
@code {
    private List<SalaryInfo> listSalarys = new();
    protected override async Task OnInitializedAsync() {
        try {
            listSalarys = await _HttpClient.GetFromJsonAsync<List<SalaryInfo>>($"api/Salary/GetInfosByUsrId?usrId={GobalManager.myInfo?.Id}");
        }
        catch (Exception ex) {
            _MessageService.Error(ex.Message);
        }
        await base.OnInitializedAsync();
    }
    private async Task OpenModalMove(int Id) {
        var modalConfig = new ModalOptions {
                    Title = "详情",
                    Draggable = true,
                    Footer = null,
                    Maximizable = true,
                    Width = "80vw",
                    Content = @<ViewSalaryManager Id="Id" />
        };

        await _modalService.CreateModalAsync(modalConfig);
    }
}
